﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace WCS.Infrastructure.EFCore;

/// <summary>
/// 订单表
/// </summary>
[Table("Order")]
[Index("CreationTime", Name = "Order_CreationTime_idx")]
[Index("IsSettlement", "IsDivided", "DividedAgreementId", Name = "Order_IsSettlement_IsDivided_DividedAgreementId_idx")]
[Index("MerchantId", "StoreId", "CodeId", Name = "Order_MerchantId_StoreId_CodeId_idx")]
[Index("OutTradeNo", Name = "Order_OutTradeNo_idx", IsUnique = true)]
[Index("PayMethod", Name = "Order_PayMethod_idx")]
[Index("PaymentStatus", Name = "Order_PaymentStatus_idx")]
[Index("TransactionNo", Name = "Order_TransactionNo_idx")]
[Index("OrderCode", Name = "Orders_OrderCode_idx", IsUnique = true)]
public partial class Order
{
    /// <summary>
    /// 订单ID
    /// </summary>
    [Key]
    [StringLength(32)]
    public string Id { get; set; } = null!;

    /// <summary>
    /// 订单编号
    /// </summary>
    [StringLength(32)]
    public string OrderCode { get; set; } = null!;

    /// <summary>
    /// 订单金额
    /// </summary>
    public long OrderAmount { get; set; }

    /// <summary>
    /// 订单类型
    /// </summary>
    public int OrderType { get; set; }

    /// <summary>
    /// 收款码ID
    /// </summary>
    [StringLength(32)]
    public string CodeId { get; set; } = null!;

    /// <summary>
    /// 门店ID
    /// </summary>
    [StringLength(32)]
    public string StoreId { get; set; } = null!;

    /// <summary>
    /// 商户ID
    /// </summary>
    [StringLength(32)]
    public string MerchantId { get; set; } = null!;

    /// <summary>
    /// 支付设备ID
    /// </summary>
    [StringLength(32)]
    public string? DeviceId { get; set; }

    /// <summary>
    /// 费率
    /// </summary>
    public decimal Rate { get; set; }

    /// <summary>
    /// 手续费
    /// </summary>
    public long Commission { get; set; }

    /// <summary>
    /// 优惠券实例ID
    /// </summary>
    [StringLength(32)]
    public string? CouponInstanceId { get; set; }

    /// <summary>
    /// 优惠金额
    /// </summary>
    public long? DiscountAmount { get; set; }

    /// <summary>
    /// 结算金额
    /// </summary>
    public long? SettlementAmount { get; set; }

    /// <summary>
    /// 平台服务费率（优惠券使用产生）
    /// </summary>
    public decimal? PlatformServiceFeeRate { get; set; }

    /// <summary>
    /// 平台服务费（优惠券使用产生）
    /// </summary>
    public long? PlatformServiceFee { get; set; }

    /// <summary>
    /// 优惠券推荐抽成金额
    /// </summary>
    public long? RecommendationCommissionAmount { get; set; }

    /// <summary>
    /// 推荐商户ID
    /// </summary>
    [StringLength(32)]
    public string? RecommendMerchantId { get; set; }

    /// <summary>
    /// 支付用户ID
    /// </summary>
    [StringLength(32)]
    public string? UserId { get; set; }

    /// <summary>
    /// 分账协议ID
    /// </summary>
    [StringLength(32)]
    public string? DividedAgreementId { get; set; }

    /// <summary>
    /// 订单快照
    /// </summary>
    [Column(TypeName = "jsonb")]
    public string? OrderSnapshot { get; set; }

    /// <summary>
    /// 累计退款金额
    /// </summary>
    public long? TotalRefundAmount { get; set; }

    /// <summary>
    /// 退款次数
    /// </summary>
    public int? RefundCount { get; set; }

    /// <summary>
    /// 退款结果状态(0=未退款,1=部分退款,2=全额退款)
    /// </summary>
    public int? RefundStatus { get; set; }

    /// <summary>
    /// 最后退款时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? LastRefundTime { get; set; }

    /// <summary>
    /// 是否结算
    /// </summary>
    public int IsSettlement { get; set; }

    /// <summary>
    /// 结算日期(根据结算周期算出 只取日期部分 时间为 00:00:00)
    /// </summary>
    [Column(TypeName = "timestamp(0) without time zone")]
    public DateTime SettlementDate { get; set; }

    /// <summary>
    /// 结算时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? SettlementTime { get; set; }

    /// <summary>
    /// 是否分账
    /// </summary>
    public int IsDivided { get; set; }

    /// <summary>
    /// 分账日期(根据分账周期算出 只取日期部分 时间为 00:00:00)
    /// </summary>
    [Column(TypeName = "timestamp(0) without time zone")]
    public DateTime DividedDate { get; set; }

    /// <summary>
    /// 分账时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? DividedTime { get; set; }

    /// <summary>
    /// 版本号
    /// </summary>
    [StringLength(256)]
    public string? Version { get; set; }

    /// <summary>
    /// 商户订单号
    /// </summary>
    [StringLength(32)]
    public string OutTradeNo { get; set; } = null!;

    /// <summary>
    /// 商户编号
    /// </summary>
    [StringLength(32)]
    public string CustomerCode { get; set; } = null!;

    /// <summary>
    /// 用户终端 IP
    /// </summary>
    [StringLength(16)]
    public string? ClientIp { get; set; }

    /// <summary>
    /// 商品订单信息
    /// </summary>
    [Column(TypeName = "jsonb")]
    public string? OrderInfo { get; set; }

    /// <summary>
    /// 支付金额，单位为分
    /// </summary>
    public long PayAmount { get; set; }

    /// <summary>
    /// 支付币种：默讣CNY人民币 
    /// </summary>
    [StringLength(5)]
    public string PayCurrency { get; set; } = null!;

    /// <summary>
    /// 是否禁止信用卡支付
    /// </summary>
    [StringLength(5)]
    public string? NoCreditCards { get; set; }

    /// <summary>
    /// 支付结果通知地址
    /// </summary>
    [StringLength(256)]
    public string NotifyUrl { get; set; } = null!;

    /// <summary>
    /// 商户支付结果展示地址
    /// </summary>
    [StringLength(256)]
    public string? RedirectUrl { get; set; }

    /// <summary>
    /// 商户备注
    /// </summary>
    [StringLength(128)]
    public string? AttachData { get; set; }

    /// <summary>
    /// 交易开始时间
    /// </summary>
    [StringLength(14)]
    public string TransactionStartTime { get; set; } = null!;

    /// <summary>
    /// 交易超时时间
    /// </summary>
    [StringLength(14)]
    public string? TransactionEndTime { get; set; }

    /// <summary>
    /// 支付方式
    /// </summary>
    [StringLength(4)]
    public string? PayMethod { get; set; }

    /// <summary>
    /// 子商户公众号appid
    /// </summary>
    [StringLength(32)]
    public string? SubAppId { get; set; }

    /// <summary>
    /// 上游商户号
    /// </summary>
    [StringLength(32)]
    public string? ChannelMchtNo { get; set; }

    /// <summary>
    /// 分期可用渠道
    /// </summary>
    [StringLength(50)]
    public string? EnablePayChannels { get; set; }

    /// <summary>
    /// 分期期数
    /// </summary>
    public int? InstalmentsNum { get; set; }

    /// <summary>
    /// 支付宝门店编号
    /// </summary>
    [StringLength(32)]
    public string? AlipayStoreCode { get; set; }

    /// <summary>
    /// 支付宝门店ID
    /// </summary>
    [StringLength(32)]
    public string? AlipayStoreId { get; set; }

    /// <summary>
    /// 付款人信息（微信、支付宝支付时有效）
    /// </summary>
    [Column(TypeName = "jsonb")]
    public string? ExtUserInfo { get; set; }

    /// <summary>
    /// 终端信息
    /// </summary>
    [Column(TypeName = "jsonb")]
    public string? TerminalInfo { get; set; }

    /// <summary>
    /// 地区信息
    /// </summary>
    [StringLength(6)]
    public string AreaInfo { get; set; } = null!;

    /// <summary>
    /// 扩展参数
    /// </summary>
    [StringLength(256)]
    public string? ExtendParams { get; set; }

    /// <summary>
    /// 优惠编码
    /// </summary>
    [StringLength(50)]
    public string? Coupons { get; set; }

    /// <summary>
    /// 随机字符串
    /// </summary>
    [StringLength(32)]
    public string NonceStr { get; set; } = null!;

    /// <summary>
    /// 扩展属性
    /// </summary>
    public string? ExtraProperties { get; set; }

    /// <summary>
    /// 并发标记
    /// </summary>
    [StringLength(40)]
    public string? ConcurrencyStamp { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 创建人ID
    /// </summary>
    [StringLength(32)]
    public string? CreatorId { get; set; }

    /// <summary>
    /// 最后修改时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? LastModificationTime { get; set; }

    /// <summary>
    /// 最后修改者ID
    /// </summary>
    [StringLength(32)]
    public string? LastModifierId { get; set; }

    /// <summary>
    /// 是否删除
    /// </summary>
    public bool IsDeleted { get; set; }

    /// <summary>
    /// 删除者ID
    /// </summary>
    [StringLength(32)]
    public string? DeleterId { get; set; }

    /// <summary>
    /// 删除时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? DeletionTime { get; set; }

    /// <summary>
    /// 应结订单金额，单位分，可选参数。
    /// </summary>
    public long? CashAmount { get; set; }

    /// <summary>
    /// 代金券金额，单位分，可选参数。
    /// </summary>
    public long? CouponAmount { get; set; }

    /// <summary>
    /// 优惠信息，使用优惠券时必须，参考 couponDetails 说明。
    /// </summary>
    public string? CouponDetails { get; set; }

    /// <summary>
    /// 分期信息，JSON 对象，分期支付时必填，参考“分期 IPInfo 对象”。
    /// </summary>
    public string? IpInfo { get; set; }

    /// <summary>
    /// 分期协议版本号，分期必需。
    /// </summary>
    [StringLength(50)]
    public string? IpProtocolVersion { get; set; }

    /// <summary>
    /// 签约折算年化利率，分期必需，详见年化内部收益率（IRR）计算公式，百分比数字，保留两位小数，示例：15.18%年化率取值：15.18。
    /// </summary>
    public float? Irr { get; set; }

    /// <summary>
    /// 年化利率计费方式，分期必需，1：单利，2：复利。
    /// </summary>
    public int? IrrType { get; set; }

    /// <summary>
    /// 支付服务费，单位分
    /// </summary>
    public long? PayServiceCharged { get; set; }

    /// <summary>
    /// 支付完成时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? PaymentTime { get; set; }

    /// <summary>
    /// 支付状态(0=处理中，1=支付成功​，2=支付失败​​，3=已撤销，4=已关闭，5=已超时​​)
    /// </summary>
    public int? PaymentStatus { get; set; }

    /// <summary>
    /// 手续费，交易过程中产生的手续费用
    /// </summary>
    public long? ProcedureFee { get; set; }

    /// <summary>
    /// 交易说明，长度为 100 位的字符串，可选参数。
    /// </summary>
    [StringLength(100)]
    public string? Remark { get; set; }

    /// <summary>
    /// 保留信息，长度为 400 位的字符串，参考“reserved 字段说明”，可选参数。
    /// </summary>
    [StringLength(400)]
    public string? Reserved { get; set; }

    /// <summary>
    /// 上游订单号
    /// </summary>
    [StringLength(64)]
    public string? ChannelOrder { get; set; }

    /// <summary>
    /// 终端名称
    /// </summary>
    [StringLength(100)]
    public string? TerminalName { get; set; }

    /// <summary>
    /// 终端号
    /// </summary>
    [StringLength(20)]
    public string? TerminalNo { get; set; }

    /// <summary>
    /// 易票联订单号
    /// </summary>
    [StringLength(32)]
    public string? TransactionNo { get; set; }

    /// <summary>
    /// 买家的支付宝唯一用户号，长度为 28 位的字符串，支付宝类交易需要返回，2088 开头的 16 位纯数字。
    /// </summary>
    [StringLength(16)]
    public string? BuyerId { get; set; }

    /// <summary>
    /// 买家的支付宝账号，长度为 100 位的字符串，支付宝类交易需要返回。
    /// </summary>
    [StringLength(100)]
    public string? BuyerLogonId { get; set; }

    /// <summary>
    /// 标签 ID，长度为 14 位的字符串，碰一碰类型交易返回。
    /// </summary>
    [StringLength(14)]
    public string? NfcTagId { get; set; }

    /// <summary>
    /// 用户在 appId 下的唯一标识，长度为 32 位的字符串，微信类交易需要返回。
    /// </summary>
    [StringLength(32)]
    public string? OpenId { get; set; }

    /// <summary>
    /// 用户在子商户 appId 下的唯一标识，长度为 32 位的字符串，微信类交易需要返回。
    /// </summary>
    [StringLength(32)]
    public string? SubOpenId { get; set; }

    /// <summary>
    /// 可退款金额（实收金额 - 累计退款金额）
    /// </summary>
    public long? RefundableAmount { get; set; }

    /// <summary>
    /// 退款处理状态(0=无退款进行中,1=退款处理中)
    /// </summary>
    public int? RefundProcessStatus { get; set; }
}
